import functools

from flask import current_app
from flask import g
from flask import session

from info.models import User


def do_index_class(value):
    if value == 0:
        return "first"
    elif value == 1:
        return "second"
    elif value == 2:
        return "third"
    return ""


def user_login_data(f):
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get("user_id", None)
        user = None
        if user_id:
            try:
                user = User.query.get(user_id)
            except Exception as ret:
                current_app.logger.error(ret)
        g.user = user
        return f(*args,**kwargs)
    return wrapper


def test(a):
    print("test function---%s" % a)


if __name__ == '__main__':
    test(9)